package org.grow.later.user;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@Component
public class Logout implements Filter {
    private Long AccessAccount = 0l;

    public synchronized Long getAccessAccount() {
        return AccessAccount;
    }

    public synchronized void increAccessAccount() {
        AccessAccount ++;
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        //
     //   System.out.println("尝试在所有处理器处理前做一些事情,如统计服务器总访问量");
        this.increAccessAccount();
     //   System.out.println("这里另外模拟做后置登出");
        String requestURI =  request.getRequestURI();
        if (requestURI.equals("/product")){
            response.sendRedirect("/user");
        }else{

            filterChain.doFilter(request,response);
        }
    }
}
